package kevin.hbase.analyse.gps;

import kevin.hbase.service.DeviceService;
import kevin.hbase.service.StopService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

@Slf4j
public class DelGpsHandler extends Thread {
    private int index;
    private final List<Map<String, Object>> list = new ArrayList<>();
    private CountDownLatch latch;
    private DeviceService deviceService;

    public DelGpsHandler(int index, DeviceService deviceService, CountDownLatch latch) {
        this.index = index;
        this.latch = latch;
        this.deviceService = deviceService;
    }

    public boolean addMap(Map<String, Object> map) {
        list.add(map);
        return true;
    }

    @Override
    public void run() {
        try {
            long start1 = System.currentTimeMillis();
            deviceService.delGps(list, index);
            long end1 = System.currentTimeMillis();
            log.info("DelGpsHandler:{} cost(ms):{}", index, end1 - start1);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            latch.countDown();
        }
    }
}
